package cn.rongdao.jrkabao.ui.IdentificationVerificate.uicomponent;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.inputmethod.FRInputMethodManager;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.ui.loan.uicomponent.CommonHeaderUIComponent;


/**
 * Created by jiangyongxing on 2017/9/19.
 * 描述：
 */

public class IDCardValidationUIComponent extends RelativeLayout {

    private EditText mEtName;
    private EditText mEtIdCardNumber;
    private TextView mTvSubmit;
    private View mShadow;
    private IdCardVerificationSubmitListener listener;
    private TextView mTvName;
    private TextView mTvIdCardNumber;
    private TextView mTvTitle;
    private CommonHeaderUIComponent mCommonHeaderUIComponent;

    public IDCardValidationUIComponent(Context context) {
        super(context);
    }

    public IDCardValidationUIComponent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public IDCardValidationUIComponent(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mEtName = (EditText) findViewById(R.id.livu_et_name);
        mEtIdCardNumber = (EditText) findViewById(R.id.livu_et_number);
        mTvSubmit = (TextView) findViewById(R.id.livu_tv_submit);
        mTvName = (TextView) findViewById(R.id.livu_tv_idcard_number);
        mTvIdCardNumber = (TextView) findViewById(R.id.livu_tv_name);
        mTvTitle = (TextView) findViewById(R.id.lch_tv_title);
        mCommonHeaderUIComponent = (CommonHeaderUIComponent) findViewById(R.id.livu_header);
        mShadow = findViewById(R.id.livu_shadow);

        initListener();
    }

    private void initListener() {
        mShadow.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });

        mTvSubmit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != listener) {
                    listener.OnIdCardVerificationSubmitListener(mEtName.getText().toString().trim(), mEtIdCardNumber.getText().toString().trim());
                }
            }
        });
    }

    public interface IdCardVerificationSubmitListener {
        void OnIdCardVerificationSubmitListener(String name, String idCardNumber);
    }

    public void setOnIdCardVerificationSubmitListener(IdCardVerificationSubmitListener listener) {
        this.listener = listener;
    }

    /**
     * Visiable表示不可用
     *
     * @param visiable
     */
    public void setContentDisable(int visiable) {
        mShadow.setVisibility(visiable);
    }

    public void setNameAndNumber(String name, String number) {
        setEditTextClearFocus();
//        setAllTextColor(getResources().getColor(R.color.c50666666));
        mEtName.setText(name);
        mEtIdCardNumber.setText(number);
        mTvSubmit.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_disable_bg));
        mTvSubmit.setText("实名已认证");
        setContentDisable(VISIBLE);

    }

    public EditText getEditText() {
        return mEtName;
    }

    public void setTitel(String title) {
        mCommonHeaderUIComponent.setContent(title);
    }


    private void setAllTextColor(int color) {
        mTvTitle.setTextColor(color);
        mTvIdCardNumber.setTextColor(color);
        mTvName.setTextColor(color);
        mEtIdCardNumber.setTextColor(color);
        mEtName.setTextColor(color);
    }

    public void setEditTextClearFocus() {
        mEtName.clearFocus();
        mEtName.setFocusable(false);
        mEtName.setFocusableInTouchMode(false);
        mEtIdCardNumber.clearFocus();
        mEtIdCardNumber.setFocusable(false);
        mEtIdCardNumber.setFocusableInTouchMode(false);
    }

    public void setEditTextFocus() {
        mEtName.setFocusable(true);
        mEtName.setFocusableInTouchMode(true);
        mEtName.requestFocus();

        FRInputMethodManager.showInputMethod(mEtName);
    }
}
